'use strict';
const { graphql, buildSchema } = require('graphql');

/*
 * schema的定义是可以定义一组复杂类型的，但是入口必须有是type Query.
 */
const schema = buildSchema(`
  type Query {
    hello: String,
    testParam: String,
    ts: TestSub,
  }
  
  type TestSub {
    someMsg: String
  }
`);

const root = {
    hello: () => {
        return `Hello world. Time is ${Date.now()}.`;
    },
    testParam: param => {
        return `Your params is ${param}.`;
    },
    TestSub_someMsg: () => {
        return 'Sub msg.';
    }
};

const queryStr = `
    { 
        hello
        testParam(param: 123)
        ts {
            someMsg
        }
    }
`;

graphql(schema, queryStr, root).then((response) => {
    console.log(response);
});